import type { RequiredDeep } from 'type-fest'

import { ajax } from '@/utils'

import type { components } from '../schema'
import type { IDeleteReq, IExportRes } from '../type'

/**
 * 登录日志接口
 */
export const loginLogApi = {
  /**
   * 获取登录日志分页
   */
  getLoginLogPage(data: IGetLoginLogPageReq): Promise<IGetLoginLogPageRes> {
    return ajax.post('/monitor/log/login/page', data)
  },
  /**
   * 导出登录日志分页
   */
  exportLoginLogPage(data: IGetLoginLogPageReq): Promise<IExportRes> {
    return ajax.post('/monitor/log/login/export', data)
  },
  /**
   * 删除登录日志
   */
  deleteLoginLog(data: IDeleteReq) {
    return ajax.delete('/monitor/log/login/delete', { data })
  },
  /**
   * 清空登录日志
   */
  clearLoginLog() {
    return ajax.delete('/monitor/log/login/clear')
  }
}

export type IGetLoginLogPageReq = components['schemas']['FindLoginLogPageDTO']
export type IGetLoginLogPageRes = RequiredDeep<
  components['schemas']['FindLoginLogPageVO']['data']
>
export type ILoginLogPageItem = IGetLoginLogPageRes['list'][0]
